package com.gx.smart.building.ui.inspection.fragment

import android.content.Intent
import android.os.Bundle
import android.view.ViewGroup
import androidx.navigation.fragment.findNavController
import com.gx.smart.base.BaseMVVMFragmentV2
import com.gx.smart.building.R
import com.gx.smart.building.databinding.FragmentInspectionSubmitResultBinding
import com.gx.smart.building.ui.inspection.viewmodel.InspectionViewModel
import com.gx.smart.building.ui.report.FaultReportActivity

class InspectionSubmitResultFragment : BaseMVVMFragmentV2<InspectionViewModel>() {
    private lateinit var viewBinding: FragmentInspectionSubmitResultBinding
    override fun onBindLayout(): Int = R.layout.fragment_inspection_submit_result

    override fun getToolbarTitle(): String = "任务完成"

    override fun onBindViewModel(): Class<InspectionViewModel> = InspectionViewModel::class.java

    override fun initContentView(root: ViewGroup) {
        viewBinding = FragmentInspectionSubmitResultBinding.inflate(layoutInflater, root, true)
    }

    override fun initData() {
        viewBinding.report.setOnClickListener {
            val assetId = requireArguments().getString("assetId")
            val assetName = requireArguments().getString("assetName")
            val planTaskAssetId = requireArguments().getString("planTaskAssetId")
            val intent = Intent(requireActivity(), FaultReportActivity::class.java)
            intent.putExtra("assetId", assetId)
            intent.putExtra("assetName", assetName)
            intent.putExtra("planTaskAssetId", planTaskAssetId)
            startActivity(intent)
            requireActivity().finish()
        }
        viewBinding.detail.setOnClickListener {
            findNavController().navigateUp()
        }
        viewBinding.list.setOnClickListener {
            findNavController().navigate(
                R.id.action_inspectionSubmitResultFragment_to_inspectionDetailFragment,
                Bundle().apply {
                    putInt("position", 1)
                })
        }
    }
}